package com.zzhrtech.wgzx_cityzen.ui.task;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.flyco.tablayout.SlidingTabLayout;
import com.zzhrtech.wgzx_cityzen.Constans;
import com.zzhrtech.wgzx_cityzen.MainActivity;
import com.zzhrtech.wgzx_cityzen.R;
import com.zzhrtech.wgzx_cityzen.adapters.task.TaskPagerAdapter;
import com.zzhrtech.wgzx_cityzen.base.BaseFragment;

import java.util.ArrayList;


/**
 * A simple {@link Fragment} subclass.
 */
public class TaskFragment extends BaseFragment {


    private String areaId = "",qudaoId="";
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private TaskPagerAdapter pagerAdapter;
    private ViewPager vp_task;
    private SlidingTabLayout tabLayout;
    public TaskFragment() {
        // Required empty public constructor
    }

    public static TaskFragment newInstance() {

        Bundle args = new Bundle();

        TaskFragment fragment = new TaskFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        setHasOptionsMenu(true);

        View view =  inflater.inflate(R.layout.fragment_task, container, false);

        vp_task = (ViewPager) view.findViewById(R.id.vp_task);
        tabLayout = (SlidingTabLayout) view.findViewById(R.id.tl_1);

        return view;
    }


    @Override
    protected void initData() {
        super.initData();

        vp_task.setAdapter(pagerAdapter);

        tabLayout.setViewPager(vp_task);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == 1 & resultCode == 3){

            pagerAdapter.notifyDataSetChanged();

        }else if (requestCode == 4 & resultCode == Activity.RESULT_OK){

            qudaoId = data.getStringExtra("qudaoid");
            areaId = data.getStringExtra("areaid");
            pagerAdapter.notifyDataSetChanged();

        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.menu_task, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.filter){

            Intent intent = new Intent(mActivity,TaskFilterActivity.class);
            startActivityForResult(intent,4);

            return true;

        }
        return super.onOptionsItemSelected(item);
    }


}
